package com.david.webtest

import android.app.Application
import android.util.Log
import com.david.webtest.utils.PreferenceUtils
import com.tencent.smtt.export.external.TbsCoreSettings
import com.tencent.smtt.sdk.QbSdk
import com.tencent.smtt.sdk.QbSdk.PreInitCallback
import java.util.*


class WebApplication: Application() {
    companion object{
        lateinit var instance:WebApplication
    }
    override fun onCreate() {
        super.onCreate()
        instance = this

        PreferenceUtils.init(this)


        // 在调用TBS初始化、创建WebView之前进行如下配置
        val map = HashMap<String, Any>()
        map.put(TbsCoreSettings.TBS_SETTINGS_USE_SPEEDY_CLASSLOADER, true)
        map.put(TbsCoreSettings.TBS_SETTINGS_USE_DEXLOADER_SERVICE, true)
        QbSdk.initTbsSettings(map)

        QbSdk.initX5Environment(this, object : PreInitCallback {
            override fun onCoreInitFinished() {}
            override fun onViewInitFinished(b: Boolean) {
                Log.e("xxx", "hasLoad$b")
                //此处将内核加载是否成功的状态保存到本地，SharePreference工具类可换为自己的
//                SharedPreferenceUtils.saveBoolean(applicationContext, "hasLoad", b)
            }
        })
    }
}